package com.starlink.common.strategy.jdnotify;

import com.starlink.common.domain.BaseEntity;
import com.starlink.common.enums.OrderTypeEnum;
import com.starlink.common.strategy.JdNotify;
import com.starlink.common.utils.AssertUtil;
import com.starlink.model.domain.OtherOrderDO;
import com.starlink.service.OtherOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class StarJDNotify implements JdNotify {
    @Autowired
    OtherOrderService otherOrderService;

    @Override
    public boolean supports(Integer orderType) {
        return orderType.equals(OrderTypeEnum.STAR.getType());
    }

    @Override
    public void handle(Long orderId) {
        // 查询订单并改为待收货
        OtherOrderDO orderDO = otherOrderService.lambdaQuery().eq(BaseEntity::getId, orderId).one();
        AssertUtil.assertNotNull(orderDO, "订单不存在");
        AssertUtil.assertTrue(orderDO.getDeliveryStatus() == 2, "订单不是运输中");
        orderDO.setDeliveryStatus(3);
        otherOrderService.saveOrUpdate(orderDO);
    }
}
